package pers.vinsonws.jianghu.clientwin.service;

import pers.vinsonws.jianghu.clientwin.global.Info;
import pers.vinsonws.jianghu.codeCompont.MsgEveryPro;
import pers.vinsonws.jianghu.tools.MergeMessage;

/**
 * @auther vinsonws
 * @date 2018/11/17 14:16
 */
public class SendAndRecvMsgService {

    /**
     * 发送聊天室消息
     * @param msg
     * @param chatRoomId
     */
    public static void sendChatRoomMsg(String msg, int chatRoomId){
        MsgEveryPro.Message.Builder builder = MsgEveryPro.Message.newBuilder();
        builder.setType(8);
        builder.setDateLong(System.currentTimeMillis());
        builder.setChatRoomOrUserRecvId(chatRoomId);
        builder.setUserSendId(Info.id);
        String[] ss = {Info.userName, msg};
        builder.setMessage(MergeMessage.infoToMessage(ss, 8));

        Info.channel.writeAndFlush(builder.build());
    }

    /**
     * 个人聊天发送信息
     * @param msg
     * @param userId
     */
    public static void sendChatOneMsg(String msg, int userId){
        MsgEveryPro.Message.Builder builder = MsgEveryPro.Message.newBuilder();
        builder.setType(7);
        builder.setDateLong(System.currentTimeMillis());
        builder.setChatRoomOrUserRecvId(userId);
        builder.setUserSendId(Info.id);
        String[] ss = {Info.userName, msg};
        builder.setMessage(MergeMessage.infoToMessage(ss, 7));

        Info.channel.writeAndFlush(builder.build());
    }
}
